package com.yixiang.np.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.yixiang.np.dao.DictionarytypeDao;
import com.yixiang.np.model.Tree;
import com.yixiang.np.model.po.Dictionarytype;
import com.yixiang.np.service.DictionarytypeServiceI;

@Service
@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)
public class DictionarytypeServiceImpl implements DictionarytypeServiceI {

	@Autowired
	private DictionarytypeDao dictionarytypeDao;

	@Override
	public void add(Dictionarytype dictionarytype) {
		dictionarytypeDao.add(dictionarytype);
	}

	@Override
	public void delete(Long id) {
		dictionarytypeDao.delete(id);
	}

	@Override
	public void edit(Dictionarytype dictionarytype) {
		dictionarytypeDao.update(dictionarytype);
	}

	@Override
	public Dictionarytype get(Long id) {
		return dictionarytypeDao.get(id);
	}

	@Override
	public List<Tree> tree() {
		List<Dictionarytype> l = null;
		List<Tree> lt = new ArrayList<Tree>();

		l = dictionarytypeDao.findAll(null);

		if ((l != null) && (l.size() > 0)) {
			for (Dictionarytype r : l) {
				Tree tree = new Tree();
				tree.setId(r.getId().toString());
				if (r.getPid() != null) {
					tree.setPid(r.getPid().toString());
					tree.setIconCls("icon_folder");
				}else{
					tree.setIconCls("icon_company");
				}
				tree.setText(r.getName());
				lt.add(tree);
			}
		}
		return lt;
	}

	 

}
